<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>

<fmt:setBundle basename="messages"/>
<script type="text/javascript" language="javascript">
	var validSubmit = true;
	
	function submitAddCostElement(form){
		var costElementId = document.getElementById('costElementId').value;
		var costElementAmount = "";
		
		if (validSubmit){
			costElementAmount = form.costElementAmount.value;
			costElementAmount = costElementAmount.replace(/,/g, "");
			
			if (isNaN(parseFloat(costElementAmount)) || parseFloat(costElementAmount) == 0.0 || parseFloat(costElementAmount)  > 99999.99){
				alert('<fmt:message key="warning.message.transports.costelement.invalid.amount"/>');
			} else {
				validSubmit = false;
				form.submit();
			}
		} else {
			alert('<fmt:message key="warning.message.common.processing"/>');
		}
	}
	
</script>
<form name="PurchaseOrderChargeForm" action="savePurchaseOrderCost.do" method="POST">
	<table width="100%" align="center" border="0">
		<tr>
			<td style="width: 100%" align="center">
				<table style="width: 340" align="center" border="0" cellspacing="1" bgcolor="#CCCCC0">
					<tr>
						<th colspan="2" align="center" class="titulocolumna">
							<fmt:message key="label.transports.costelements.addCostElement"/>
						</th>
					</tr>
					<tr>
						<td class="etiqueta" style="width: 35%">
							
						</td>
						<td class="etiqueta_campo">
							<input type="hidden" name="purchaseOrderChargeView.purchaseOrderId"  value="<c:out value="${purchaseOrderId}"/>" />
						</td>
					</tr>
					<tr>
						<td class="etiqueta" style="width: 35%">
							<fmt:message key="label.transports.costelements.code"/>
						</td>
						<td class="etiqueta_campo">
							<select name="purchaseOrderChargeView.purchaseOrderChargeTypeId" id="costElementId" class="campo_texto" style="width: 100%">
								<c:forEach items="${costElementsList}" var="costElementView">
									<option value="<c:out value="${costElementView.costElementID}"/>"><c:out value="${costElementView.costElementCode}"/></option>
								</c:forEach>							
							</select>
						</td>
					</tr>
					<tr>
						<td class="etiqueta" style="width: 35%">
							<fmt:message key="label.transports.costelements.amount"/>
						</td>
						<td class="etiqueta_campo">
							<input type="text" id="costElementAmount" name="purchaseOrderChargeView.purchaseOrderAmount" onkeydown="return (numeric(event, 1) && noPaste(event, this));" onkeyup="extractNumber(this,4,false);" size="15" maxlength="10" class="campo_texto" style="text-align: right;"/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td height="10">
			</td>
		</tr>
		<tr>
			<td width="100%">
				<table align="center" width="340" cellpadding="2" cellspacing="1" border="0" bgcolor="#CCCCC0">
					<tr>
						<td style="text-align: center; vertical-align: middle; width: 50%" class="columnadatoPar">
							<input type="button" value="<fmt:message key="label.common.add"/>" onclick="submitAddCostElement(PurchaseOrderChargeForm);" class="boton"/>
							<input type="button"  value="<fmt:message key="label.common.cancel"/>"  onclick="location.href = 'showEditPurchaseOrder.do'"  class="boton"/>&nbsp;
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
